home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / elispman.lha / elispman / elisp-13 (.txt) < prev    next >
GNU Info File  |  1993-06-01  |  51KB  |  926 lines

  1. This is Info file elisp, produced by Makeinfo-1.55 from the input file
  2. elisp.texi.
  3.    This is edition 2.0 of the GNU Emacs Lisp Reference Manual, for
  4. Emacs Version 19.
  5.    Published by the Free Software Foundation, 675 Massachusetts Avenue,
  6. Cambridge, MA 02139 USA
  7.    Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  8.    Permission is granted to make and distribute verbatim copies of this
  9. manual provided the copyright notice and this permission notice are
  10. preserved on all copies.
  11.    Permission is granted to copy and distribute modified versions of
  12. this manual under the conditions for verbatim copying, provided that
  13. the entire resulting derived work is distributed under the terms of a
  14. permission notice identical to this one.
  15.    Permission is granted to copy and distribute translations of this
  16. manual into another language, under the above conditions for modified
  17. versions, except that this permission notice may be stated in a
  18. translation approved by the Foundation.
  19. File: elisp,  Node: Yes-or-No Queries,  Next: Multiple Queries,  Prev: Completion,  Up: Minibuffers
  20. Yes-or-No Queries
  21. =================
  22.    This section describes functions used to ask the user a yes-or-no
  23. question.  The function `y-or-n-p' can be answered with a single
  24. character; it is useful for questions where an inadvertent wrong answer
  25. will not have serious consequences.  `yes-or-no-p' is suitable for more
  26. momentous questions, since it requires three or four characters to
  27. answer.
  28.    Strictly speaking, `yes-or-no-p' uses the minibuffer and `y-or-n-p'
  29. does not; but it seems best to describe them together.
  30.  - Function: y-or-n-p PROMPT
  31.      This function asks the user a question, expecting input in the echo
  32.      area.  It returns `t' if the user types `y', `nil' if the user
  33.      types `n'.  This function also accepts SPC to mean yes and DEL to
  34.      mean no.  It accepts `C-]' to mean "quit", like `C-g', because the
  35.      question might look like a minibuffer and for that reason the user
  36.      might try to use `C-]' to get out.  The answer is a single
  37.      character, with no RET needed to terminate it.  Upper and lower
  38.      case are equivalent.
  39.      "Asking the question" means printing PROMPT in the echo area,
  40.      followed by the string `(y or n) '.  If the input is not one of
  41.      the expected answers (`y', `n', `SPC', `DEL', or something that
  42.      quits), the function responds `Please answer y or n.', and repeats
  43.      the request.
  44.      This function does not actually use the minibuffer, since it does
  45.      not allow editing of the answer.  It actually uses the echo area
  46.      (*note The Echo Area::.), which uses the same screen space as the
  47.      minibuffer.  The cursor moves to the echo area while the question
  48.      is being asked.
  49.      The meanings of answers, even `y' and `n', are not hardwired.
  50.      They are controlled by the keymap `query-replace-map'.  *Note
  51.      Replacement::.
  52.      In the following example, the user first types `q', which is
  53.      invalid.  At the next prompt the user types `n'.
  54.           (y-or-n-p "Do you need a lift? ")
  55.           
  56.           ;; After evaluating the preceding expression,
  57.           ;;   the following prompt appears in the echo area:
  58.           ---------- Echo area ----------
  59.           Do you need a lift? (y or n)
  60.           ---------- Echo area ----------
  61.           
  62.           ;; If the user then types `q', the following appears:
  63.           ---------- Echo area ----------
  64.           Please answer y or n.  Do you need a lift? (y or n)
  65.           ---------- Echo area ----------
  66.           
  67.           ;; When the user types a valid answer,
  68.           ;;   it is displayed after the question:
  69.           ---------- Echo area ----------
  70.           Do you need a lift? (y or n) y
  71.           ---------- Echo area ----------
  72.      Note that we show successive lines of echo area messages here.
  73.      Only one actually appears on the screen at a time.
  74.  - Function: yes-or-no-p PROMPT
  75.      This function asks the user a question, expecting input in
  76.      minibuffer.  It returns `t' if the user enters `yes', `nil' if the
  77.      user types `no'.  The user must type RET to finalize the response.
  78.      Upper and lower case are equivalent.
  79.      `yes-or-no-p' starts by displaying PROMPT in the echo area,
  80.      followed by `(yes or no) '.  The user must type one of the
  81.      expected responses; otherwise, the function responds `Please answer
  82.      yes or no.', waits about two seconds and repeats the request.
  83.      `yes-or-no-p' requires more work from the user than `y-or-n-p' and
  84.      is appropriate for more crucial decisions.
  85.      Here is an example:
  86.           (yes-or-no-p "Do you really want to remove everything? ")
  87.           
  88.           ;; After evaluating the preceding expression,
  89.           ;;   the following prompt appears,
  90.           ;;   with an empty minibuffer:
  91.           ---------- Buffer: minibuffer ----------
  92.           Do you really want to remove everything? (yes or no)
  93.           ---------- Buffer: minibuffer ----------
  94.      If the user first types `y RET', which is invalid because this
  95.      function demands the entire word `yes', it responds by displaying
  96.      these prompts, with a brief pause between them:
  97.           ---------- Buffer: minibuffer ----------
  98.           Please answer yes or no.
  99.           Do you really want to remove everything? (yes or no)
  100.           ---------- Buffer: minibuffer ----------
  101. File: elisp,  Node: Multiple Queries,  Next: Minibuffer Misc,  Prev: Yes-or-No Queries,  Up: Minibuffers
  102. Asking Multiple Y-or-N Queries
  103. ==============================
  104.  - Function: map-y-or-n-p PROMPTER ACTOR LIST &optional HELP
  105.           ACTION-ALIST
  106.      This function, new in Emacs 19, asks the user a series of
  107.      questions, reading a single-character answer in the echo area for
  108.      each one.
  109.      The value of LIST specifies what varies from question to question
  110.      within the series.  It should be either a list of objects or a
  111.      generator function.  If it is a function, it should expect no
  112.      arguments, and should return either the next object or `nil'
  113.      meaning there are no more questions.
  114.      The argument PROMPTER specifies how to ask each question.  If
  115.      PROMPTER is a string, the question text is computed like this:
  116.           (format PROMPTER OBJECT)
  117.      where OBJECT is the next object to ask about (as obtained from
  118.      LIST).
  119.      If not a string, PROMPTER should be a function of one argument
  120.      (the next object to ask about) and should return the question text.
  121.      The argument ACTOR says how to act on the answers that the user
  122.      gives.  It should be a function of one argument, and it is called
  123.      with each object that the user says yes for.  Its argument is
  124.      always an object obtained from LIST.
  125.      If the argument HELP is given, it should be a list of this form:
  126.           (SINGULAR PLURAL ACTION)
  127.      where SINGULAR is a string containing a singular noun that
  128.      describes the objects conceptually being acted on, PLURAL is the
  129.      corresponding plural noun, and ACTION is a transitive verb
  130.      describing what ACTOR does.
  131.      If you don't specify HELP, the default is `("object" "objects"
  132.      "act on")'.
  133.      Each time a question is asked, the user may enter `y', `Y', or SPC
  134.      to act on that object; `n', `N', or DEL to skip that object; `!'
  135.      to act on all following objects; ESC or `q' to exit (skip all
  136.      following objects); `.' (period) to act on the current object and
  137.      then exit; or `C-h' to get help.  These are the same answers that
  138.      `query-replace' accepts.  The keymap `query-replace-map' defines
  139.      their meaning for `map-y-or-n-p' as well as for `query-replace';
  140.      see *Note Replacement::.
  141.      You can use ACTION-ALIST to specify additional possible answers
  142.      and what they mean.  It is an alist of elements of the form `(CHAR
  143.      FUNCTION HELP)', each of which defines one additional answer.  In
  144.      this element, CHAR is a character (the answer); FUNCTION is a
  145.      function of one argument (an object from LIST); HELP is a string.
  146.      When the user responds with CHAR, `map-y-or-n-p' calls FUNCTION.
  147.      If it returns non-`nil', the object is considered "acted upon",
  148.      and `map-y-or-n-p' advances to the next object in LIST.  If it
  149.      returns `nil', the prompt is repeated for the same object.
  150.      The return value of `map-y-or-n-p' is the number of objects acted
  151.      on.
  152. File: elisp,  Node: Minibuffer Misc,  Prev: Multiple Queries,  Up: Minibuffers
  153. Minibuffer Miscellany
  154. =====================
  155.    This section describes some basic functions and variables related to
  156. minibuffers.
  157.  - Command: exit-minibuffer
  158.      This command exits the active minibuffer.  It is normally bound to
  159.      keys in minibuffer local keymaps.
  160.  - Command: self-insert-and-exit
  161.      This command exits the active minibuffer after inserting the last
  162.      character typed on the keyboard (found in `last-command-char';
  163.      *note Command Loop Info::.).
  164.  - Command: previous-history-element N
  165.      This command replaces the minibuffer contents with the value of the
  166.      Nth previous (older) history element.
  167.  - Command: next-history-element N
  168.      This command replaces the minibuffer contents with the value of the
  169.      Nth more recent history element.
  170.  - Command: previous-matching-history-element PATTERN
  171.      This command replaces the minibuffer contents with the value of the
  172.      previous (older) history element that matches PATTERN.  At the
  173.      time of printing, we have not made a final decision about how to
  174.      get the pattern interactively or how to match it against history
  175.      elements.
  176.  - Command: next-matching-history-element PATTERN
  177.      This command replaces the minibuffer contents with the value of the
  178.      next (newer) history element that matches PATTERN.
  179.  - Variable: minibuffer-help-form
  180.      The current value of this variable is used to rebind `help-form'
  181.      locally inside the minibuffer (*note Help Functions::.).
  182.  - Function: minibuffer-window &optional FRAME
  183.      This function returns the window that is used for the minibuffer.
  184.      In Emacs 18, there is one and only one minibuffer window; this
  185.      window always exists and cannot be deleted.  In Emacs 19, each
  186.      frame can have its own minibuffer, and this function returns the
  187.      minibuffer window used for frame FRAME (which defaults to the
  188.      currently selected frame).
  189.  - Function: window-minibuffer-p WINDOW
  190.      This function returns non-`nil' if WINDOW is a minibuffer window.
  191.    It is not correct to determine whether a given window is a
  192. minibuffer by comparing it with the result of `(minibuffer-window)',
  193. because there can be more than one minibuffer window there is more than
  194. one frame.
  195.  - Variable: minibuffer-scroll-window
  196.      If the value of this variable is non-`nil', it should be a window
  197.      object.  When the function `scroll-other-window' is called in the
  198.      minibuffer, it scrolls this window.
  199.    Finally, some functions and variables deal with recursive minibuffers
  200. (*note Recursive Editing::.):
  201.  - Function: minibuffer-depth
  202.      This function returns the current depth of activations of the
  203.      minibuffer, a nonnegative integer.  If no minibuffers are active,
  204.      it returns zero.
  205.  - User Option: enable-recursive-minibuffers
  206.      If this variable is non-`nil', you can invoke commands (such as
  207.      `find-file') which use minibuffers even while in the minibuffer
  208.      window.  Such invocation produces a recursive editing level for a
  209.      new minibuffer.  The outer-level minibuffer is invisible while you
  210.      are editing the inner one.
  211.      This variable only affects invoking the minibuffer while the
  212.      minibuffer window is selected.   If you switch windows while in the
  213.      minibuffer, you can always invoke minibuffer commands while some
  214.      other window is selected.
  215.    If a command name has a property `enable-recursive-minibuffers'
  216. which is non-`nil', then the command can use the minibuffer to read
  217. arguments even if it is invoked from the minibuffer.  The minibuffer
  218. command `next-matching-history-element' (normally bound to `M-s' in the
  219. minibuffer) uses this feature.
  220. File: elisp,  Node: Command Loop,  Next: Keymaps,  Prev: Minibuffers,  Up: Top
  221. Command Loop
  222. ************
  223.    When you run Emacs, it enters the "editor command loop" almost
  224. immediately.  This loop reads key sequences, executes their definitions,
  225. and displays the results.  In this chapter, we describe how these things
  226. are done, and the subroutines that allow Lisp programs to do them.
  227. * Menu:
  228. * Command Overview::    How the command loop reads commands.
  229. * Defining Commands::   Specifying how a function should read arguments.
  230. * Interactive Call::    Calling a command, so that it will read arguments.
  231. * Command Loop Info::   Variables set by the command loop for you to examine.
  232. * Input Events::    What input looks like when you read it.
  233. * Reading Input::       How to read input events from the keyboard or mouse.
  234. * Waiting::             Waiting for user input or elapsed time.
  235. * Quitting::            How `C-g' works.  How to catch or defer quitting.
  236. * Prefix Command Arguments::    How the commands to set prefix args work.
  237. * Recursive Editing::   Entering a recursive edit,
  238.                           and why you usually shouldn't.
  239. * Disabling Commands::  How the command loop handles disabled commands.
  240. * Command History::     How the command history is set up, and how accessed.
  241. * Keyboard Macros::     How keyboard macros are implemented.
  242. File: elisp,  Node: Command Overview,  Next: Defining Commands,  Up: Command Loop
  243. Command Loop Overview
  244. =====================
  245.    The first thing the command loop must do is read a key sequence,
  246. which is a sequence of events that translates into a command.  It does
  247. this by calling the function `read-key-sequence'.  Your Lisp code can
  248. also call this function (*note Key Sequence Input::.).  Lisp programs
  249. can also do input at a lower level with `read-event' (*note Reading One
  250. Event::.) or discard pending input with `discard-input' (*note Peeking
  251. and Discarding::.).
  252.    The key sequence is translated into a command through the currently
  253. active keymaps.  *Note Key Lookup::, for information on how this is
  254. done.  The result should be a keyboard macro or an interactively
  255. callable function.  If the key is `M-x', then it reads the name of
  256. another command, which is used instead.  This is done by the command
  257. `execute-extended-command' (*note Interactive Call::.).
  258.    Once the command is chosen, it must be executed, which includes
  259. reading arguments to be given to it.  This is done by calling
  260. `command-execute' (*note Interactive Call::.).  For commands written in
  261. Lisp, the `interactive' specification says how to read the arguments.
  262. This may use the prefix argument (*note Prefix Command Arguments::.) or
  263. may read with prompting in the minibuffer (*note Minibuffers::.).  For
  264. example, the command `find-file' has an `interactive' specification
  265. which says to read a file name using the minibuffer.  The command's
  266. function body does not use the minibuffer; if you call this command
  267. from Lisp code as a function, you must supply the file name string as
  268. an ordinary Lisp function argument.
  269.    If the command is a string or vector (i.e., a keyboard macro) then
  270. `execute-kbd-macro' is used to execute it.  You can call this function
  271. yourself (*note Keyboard Macros::.).
  272.    If a command runs away, typing `C-g' terminates its execution
  273. immediately.  This is called "quitting" (*note Quitting::.).
  274.  - Variable: pre-command-hook
  275.      The editor command loop runs this normal hook before each command.
  276.  - Variable: post-command-hook
  277.      The editor command loop runs this normal hook after each command.
  278. File: elisp,  Node: Defining Commands,  Next: Interactive Call,  Prev: Command Overview,  Up: Command Loop
  279. Defining Commands
  280. =================
  281.    A Lisp function becomes a command when its body contains, at top
  282. level, a form which calls the special form `interactive'.  This form
  283. does nothing when actually executed, but its presence serves as a flag
  284. to indicate that interactive calling is permitted.  Its argument
  285. controls the reading of arguments for an interactive call.
  286. * Menu:
  287. * Using Interactive::     General rules for `interactive'.
  288. * Interactive Codes::     The standard letter-codes for reading arguments
  289.                              in various ways.
  290. * Interactive Examples::  Examples of how to read interactive arguments.
  291. File: elisp,  Node: Using Interactive,  Next: Interactive Codes,  Up: Defining Commands
  292. Using `interactive'
  293. -------------------
  294.    This section describes how to write the `interactive' form that
  295. makes a Lisp function an interactively-callable command.
  296.  - Special Form: interactive ARG-DESCRIPTOR
  297.      This special form declares that the function in which it appears
  298.      is a command, and that it may therefore be called interactively
  299.      (via `M-x' or by entering a key sequence bound to it).  The
  300.      argument ARG-DESCRIPTOR declares the way the arguments to the
  301.      command are to be computed when the command is called
  302.      interactively.
  303.      A command may be called from Lisp programs like any other
  304.      function, but then the arguments are supplied by the caller and
  305.      ARG-DESCRIPTOR has no effect.
  306.      The `interactive' form has its effect because the command loop
  307.      (actually, its subroutine `call-interactively') scans through the
  308.      function definition looking for it, before calling the function.
  309.      Once the function is called, all its body forms including the
  310.      `interactive' form are executed, but at this time `interactive'
  311.      simply returns `nil' without even evaluating its argument.
  312.    There are three possibilities for the argument ARG-DESCRIPTOR:
  313.    * It may be omitted or `nil'; then the command is called with no
  314.      arguments.  This leads quickly to an error if the command requires
  315.      one or more arguments.
  316.    * It may be a Lisp expression that is not a string; then it should
  317.      be a form that is evaluated to get a list of arguments to pass to
  318.      the command.
  319.    * It may be a string; then its contents should consist of a code
  320.      character followed by a prompt (which some code characters use and
  321.      some ignore).  The prompt ends either with the end of the string
  322.      or with a newline.  Here is a simple example:
  323.           (interactive "bFrobnicate buffer: ")
  324.      The code letter `b' says to read the name of an existing buffer,
  325.      with completion.  The buffer name is the sole argument passed to
  326.      the command.  The rest of the string is a prompt.
  327.      If there is a newline character in the string, it terminates the
  328.      prompt.  If the string does not end there, then the rest of the
  329.      string should contain another code character and prompt,
  330.      specifying another argument.  You can specify any number of
  331.      arguments in this way.
  332.      The prompt string can use `%' to include previous argument values
  333.      in the prompt.  This is done using `format' (*note Formatting
  334.      Strings::.).  For example, here is how you could read the name of
  335.      an existing buffer followed by a new name to give to that buffer:
  336.           (interactive "bBuffer to rename: \nsRename buffer %s to: ")
  337.      If the first character in the string is `*', then an error is
  338.      signaled if the buffer is read-only.
  339.      If the first character in the string is `@', and if the key
  340.      sequence used to invoke the command includes any mouse events, then
  341.      the window associated with the first of those events is selected
  342.      before the command is run.
  343.      You can use `*' and `@' together; the order does not matter.
  344.      Actual reading of arguments is controlled by the rest of the prompt
  345.      string (starting with the first character that is not `*' or `@').
  346. File: elisp,  Node: Interactive Codes,  Next: Interactive Examples,  Prev: Using Interactive,  Up: Defining Commands
  347. Code Characters for `interactive'
  348. ---------------------------------
  349.    The code character descriptions below contain a number of key words,
  350. defined here as follows:
  351. Completion
  352.      Provide completion.  TAB, SPC, and RET perform name completion
  353.      because the argument is read using `completing-read' (*note
  354.      Completion::.).  `?' displays a list of possible completions.
  355. Existing
  356.      Require the name of an existing object.  An invalid name is not
  357.      accepted; the commands to exit the minibuffer do not exit if the
  358.      current input is not valid.
  359. Default
  360.      A default value of some sort is used if the user enters no text in
  361.      the minibuffer.  The default depends on the code character.
  362. No I/O
  363.      This code letter computes an argument without reading any input.
  364.      Therefore, it does not use a prompt string, and any prompt string
  365.      you supply is ignored.
  366. Prompt
  367.      A prompt immediately follows the code character.  The prompt ends
  368.      either with the end of the string or with a newline.
  369. Special
  370.      This code character is meaningful only at the beginning of the
  371.      interactive string, and it does not look for a prompt or a newline.
  372.      It is a single, isolated character.
  373.    Here are the code character descriptions for use with `interactive':
  374.      Signal an error if the current buffer is read-only.  Special.
  375.      Select the window mentioned in the first mouse event in the key
  376.      sequence that invoked this command.  Special.
  377.      A function name (i.e., a symbol which is `fboundp').  Existing,
  378.      Completion, Prompt.
  379.      The name of an existing buffer.  By default, uses the name of the
  380.      current buffer (*note Buffers::.).  Existing, Completion, Default,
  381.      Prompt.
  382.      A buffer name.  The buffer need not exist.  By default, uses the
  383.      name of a recently used buffer other than the current buffer.
  384.      Completion, Prompt.
  385.      A character.  The cursor does not move into the echo area.  Prompt.
  386.      A command name (i.e., a symbol satisfying `commandp').  Existing,
  387.      Completion, Prompt.
  388.      The position of point as a number (*note Point::.).  No I/O.
  389.      A directory name.  The default is the current default directory of
  390.      the current buffer, `default-directory' (*note System
  391.      Environment::.).  Existing, Completion, Default, Prompt.
  392.      The first or next mouse event in the key sequence that invoked the
  393.      command.  More precisely, `e' gets events which are lists, so you
  394.      can look at the data in the lists.  *Note Input Events::.  No I/O.
  395.      You can use `e' more than once in a single command's interactive
  396.      specification.  If the key sequence which invoked the command has
  397.      N events with parameters, the Nth `e' provides the Nth list event.
  398.      Events which are not lists, such as function keys and ASCII
  399.      characters, do not count where `e' is concerned.
  400.      Even though `e' does not use a prompt string, you must follow it
  401.      with a newline if it is not the last code character.
  402.      A file name of an existing file (*note File Names::.).  The default
  403.      directory is `default-directory'.  Existing, Completion, Default,
  404.      Prompt.
  405.      A file name.  The file need not exist.  Completion, Default,
  406.      Prompt.
  407.      A key sequence (*note Keymap Terminology::.).  This keeps reading
  408.      events until a command (or undefined command) is found in the
  409.      current key maps.  The key sequence argument is represented as a
  410.      string or vector.  The cursor does not move into the echo area.
  411.      Prompt.
  412.      This kind of input is used by commands such as `describe-key' and
  413.      `global-set-key'.
  414.      The position of the mark as a number.  No I/O.
  415.      A number read with the minibuffer.  If the input is not a number,
  416.      the user is asked to try again.  The prefix argument, if any, is
  417.      not used.  Prompt.
  418.      The raw prefix argument.  If the prefix argument is `nil', then a
  419.      number is read as with `n'.  Requires a number.  Prompt.
  420.      The numeric prefix argument.  (Note that this `p' is lower case.)
  421.      No I/O.
  422.      The raw prefix argument.  (Note that this `P' is upper case.)
  423.      *Note Prefix Command Arguments::.  No I/O.
  424.      Point and the mark, as two numeric arguments, smallest first.
  425.      This is the only code letter that specifies two successive
  426.      arguments rather than one.  No I/O.
  427.      Arbitrary text, read in the minibuffer and returned as a string
  428.      (*note Text from Minibuffer::.).  Terminate the input with either
  429.      LFD or RET.  (`C-q' may be used to include either of these
  430.      characters in the input.)  Prompt.
  431.      An interned symbol whose name is read in the minibuffer.  Any
  432.      whitespace character terminates the input.  (Use `C-q' to include
  433.      whitespace in the string.)  Other characters that normally
  434.      terminate a symbol (e.g., parentheses and brackets) do not do so
  435.      here.  Prompt.
  436.      A variable declared to be a user option (i.e., satisfying the
  437.      predicate `user-variable-p').  *Note High-Level Completion::.
  438.      Existing, Completion, Prompt.
  439.      A Lisp object specified in printed representation, terminated with
  440.      a LFD or RET.  The object is not evaluated.  *Note Object from
  441.      Minibuffer::.  Prompt.
  442.      A Lisp form is read as with `x', but then evaluated so that its
  443.      value becomes the argument for the command.  Prompt.
  444. File: elisp,  Node: Interactive Examples,  Prev: Interactive Codes,  Up: Defining Commands
  445. Examples of Using `interactive'
  446. -------------------------------
  447.    Here are some examples of `interactive':
  448.      (defun foo1 ()              ; `foo1' takes no arguments,
  449.          (interactive)           ;   just moves forward two words.
  450.          (forward-word 2))
  451.           => foo1
  452.      
  453.      (defun foo2 (n)             ; `foo2' takes one argument,
  454.          (interactive "p")       ;   which is the numeric prefix.
  455.          (forward-word (* 2 n)))
  456.           => foo2
  457.      
  458.      (defun foo3 (n)             ; `foo3' takes one argument,
  459.          (interactive "nCount:") ;   which is read with the Minibuffer.
  460.          (forward-word (* 2 n)))
  461.           => foo3
  462.      
  463.      (defun three-b (b1 b2 b3)
  464.        "Select three existing buffers.
  465.      Put them into three windows, selecting the last one."
  466.          (interactive "bBuffer1:\nbBuffer2:\nbBuffer3:")
  467.          (delete-other-windows)
  468.          (split-window (selected-window) 8)
  469.          (switch-to-buffer b1)
  470.          (other-window 1)
  471.          (split-window (selected-window) 8)
  472.          (switch-to-buffer b2)
  473.          (other-window 1)
  474.          (switch-to-buffer b3))
  475.           => three-b
  476.      (three-b "*scratch*" "declarations.texi" "*mail*")
  477.           => nil
  478. File: elisp,  Node: Interactive Call,  Next: Command Loop Info,  Prev: Defining Commands,  Up: Command Loop
  479. Interactive Call
  480. ================
  481.    After the command loop has translated a key sequence into a
  482. definition, it invokes that definition using the function
  483. `command-execute'.  If the definition is a function that is a command,
  484. `command-execute' calls `call-interactively', which reads the arguments
  485. and calls the command.  You can also call these functions yourself.
  486.  - Function: commandp OBJECT
  487.      Returns `t' if OBJECT is suitable for calling interactively; that
  488.      is, if OBJECT is a command.  Otherwise, returns `nil'.
  489.      The interactively callable objects include strings and vectors
  490.      (treated as keyboard macros), lambda expressions that contain a
  491.      top-level call to `interactive', byte-code function objects,
  492.      autoload objects that are declared as interactive (non-`nil'
  493.      fourth argument to `autoload'), and some of the primitive
  494.      functions.
  495.      A symbol is `commandp' if its function definition is `commandp'.
  496.      Keys and keymaps are not commands.  Rather, they are used to look
  497.      up commands (*note Keymaps::.).
  498.      See `documentation' in *Note Accessing Documentation::, for a
  499.      realistic example of using `commandp'.
  500.  - Function: call-interactively COMMAND &optional RECORD-FLAG
  501.      This function calls the interactively callable function COMMAND,
  502.      reading arguments according to its interactive calling
  503.      specifications.  An error is signaled if COMMAND cannot be called
  504.      interactively (i.e., it is not a command).  Note that keyboard
  505.      macros (strings and vectors) are not accepted, even though they
  506.      are considered commands.
  507.      If RECORD-FLAG is non-`nil', then this command and its arguments
  508.      are unconditionally added to the list `command-history'.
  509.      Otherwise, the command is added only if it uses the minibuffer to
  510.      read an argument.  *Note Command History::.
  511.  - Function: command-execute COMMAND &optional RECORD-FLAG
  512.      This function executes COMMAND as an editing command.  The
  513.      argument COMMAND must satisfy the `commandp' predicate; i.e., it
  514.      must be an interactively callable function or a string.
  515.      A string or vector as COMMAND is executed with
  516.      `execute-kbd-macro'.  A function is passed to
  517.      `call-interactively', along with the optional RECORD-FLAG.
  518.      A symbol is handled by using its function definition in its place.
  519.      A symbol with an `autoload' definition counts as a command if it
  520.      was declared to stand for an interactively callable function.
  521.      Such a definition is handled by loading the specified library and
  522.      then rechecking the definition of the symbol.
  523.  - Command: execute-extended-command PREFIX-ARGUMENT
  524.      This function reads a command name from the minibuffer using
  525.      `completing-read' (*note Completion::.).  Then it uses
  526.      `command-execute' to call the specified command.  Whatever that
  527.      command returns becomes the value of `execute-extended-command'.
  528.      If the command asks for a prefix argument, the value
  529.      PREFIX-ARGUMENT is supplied.  If `execute-extended-command' is
  530.      called interactively, the current raw prefix argument is used for
  531.      PREFIX-ARGUMENT, and thus passed on to whatever command is run.
  532.      `execute-extended-command' is the normal definition of `M-x', so
  533.      it uses the string `M-x ' as a prompt.  (It would be better to
  534.      take the prompt from the events used to invoke
  535.      `execute-extended-command', but that is painful to implement.)  A
  536.      description of the value of the prefix argument, if any, also
  537.      becomes part of the prompt.
  538.           (execute-extended-command 1)
  539.           ---------- Buffer: Minibuffer ----------
  540.           M-x forward-word RET
  541.           ---------- Buffer: Minibuffer ----------
  542.                => t
  543.  - Function: interactive-p
  544.      This function returns `t' if the containing function (the one that
  545.      called `interactive-p') was called interactively, with the function
  546.      `call-interactively'.  (It makes no difference whether
  547.      `call-interactively' was called from Lisp or directly from the
  548.      editor command loop.)  Note that if the containing function was
  549.      called by Lisp evaluation (or with `apply' or `funcall'), then it
  550.      was not called interactively.
  551.      The usual application of `interactive-p' is for deciding whether to
  552.      print an informative message.  As a special exception,
  553.      `interactive-p' returns `nil' whenever a keyboard macro is being
  554.      run.  This is to suppress the informative messages and speed
  555.      execution of the macro.
  556.      For example:
  557.           (defun foo ()
  558.             (interactive)
  559.             (and (interactive-p)
  560.                  (message "foo")))
  561.                => foo
  562.           
  563.           (defun bar ()
  564.             (interactive)
  565.             (setq foobar (list (foo) (interactive-p))))
  566.                => bar
  567.           
  568.           ;; Type `M-x foo'.
  569.                -| foo
  570.           
  571.           ;; Type `M-x bar'.
  572.           ;; This does not print anything.
  573.           
  574.           foobar
  575.                => (nil t)
  576. File: elisp,  Node: Command Loop Info,  Next: Input Events,  Prev: Interactive Call,  Up: Command Loop
  577. Information from the Command Loop
  578. =================================
  579.    The editor command loop sets several Lisp variables to keep status
  580. records for itself and for commands that are run.
  581.  - Variable: last-command
  582.      This variable records the name of the previous command executed by
  583.      the command loop (the one before the current command).  Normally
  584.      the value is a symbol with a function definition, but this is not
  585.      guaranteed.
  586.      The value is set by copying the value of `this-command' when a
  587.      command returns to the command loop, except when the command
  588.      specifies a prefix argument for the following command.
  589.  - Variable: this-command
  590.      This variable records the name of the command now being executed by
  591.      the editor command loop.  Like `last-command', it is normally a
  592.      symbol with a function definition.
  593.      This variable is set by the command loop just before the command
  594.      is run, and its value is copied into `last-command' when the
  595.      command finishes (unless the command specifies a prefix argument
  596.      for the following command).
  597.      Some commands change the value of this variable during their
  598.      execution, simply as a flag for whatever command runs next.  In
  599.      particular, the functions that kill text set `this-command' to
  600.      `kill-region' so that any kill commands immediately following will
  601.      know to append the killed text to the previous kill.
  602.  - Function: this-command-keys
  603.      This function returns a string or vector containing the key
  604.      sequence that invoked the present command, plus any previous
  605.      commands that generated the prefix argument for this command.  The
  606.      value is a string if all those events were characters.  *Note
  607.      Input Events::.
  608.           (this-command-keys)
  609.           ;; Now type `C-u C-x C-e'.
  610.                => "^U^X^E"
  611.  - Variable: last-nonmenu-event
  612.      This variable holds the last input event read as part of a key
  613.      sequence, aside from events resulting from mouse menus.
  614.      One use of this variable is to figure out a good default location
  615.      to pop up another menu.
  616.  - Variable: last-command-event
  617.  - Variable: last-command-char
  618.      This variable is set to the last input event that was read by the
  619.      command loop as part of a command.  The principal use of this
  620.      variable is in `self-insert-command', which uses it to decide which
  621.      character to insert.
  622.           last-command-char
  623.           ;; Now type `C-u C-x C-e'.
  624.                => 5
  625.      The value is 5 because that is the ASCII code for `C-e'.
  626.      The alias `last-command-char' exists for compatibility with Emacs
  627.      version 18.
  628.  - Variable: last-event-frame
  629.      This variable records which frame the last input event was
  630.      directed to.  Usually this is the frame that was selected when the
  631.      event was generated, but if that frame has redirected input focus
  632.      to another frame, the value is the frame to which the event was
  633.      redirected.  *Note Input Focus::.
  634.  - Variable: echo-keystrokes
  635.      This variable determines how much time should elapse before command
  636.      characters echo.  Its value must be an integer, which specifies the
  637.      number of seconds to wait before echoing.  If the user types a
  638.      prefix key (say `C-x') and then delays this many seconds before
  639.      continuing, the key `C-x' is echoed in the echo area.  Any
  640.      subsequent characters in the same command will be echoed as well.
  641.      If the value is zero, then command input is not echoed.
  642. File: elisp,  Node: Input Events,  Next: Reading Input,  Prev: Command Loop Info,  Up: Command Loop
  643. Input Events
  644. ============
  645.    The Emacs command loop reads a sequence of "input events" that
  646. represent keyboard or mouse activity.  The events for keyboard activity
  647. are characters or symbols; mouse events are always lists.  This section
  648. describes the representation and meaning of input events in detail.
  649.    A command invoked using events that are lists can get the full
  650. values of these events using the `e' interactive code.  *Note
  651. Interactive Codes::.
  652.    A key sequence that starts with a mouse event is read using the
  653. keymaps of the buffer in the window that the mouse was in, not the
  654. current buffer.  This does not imply that clicking in a window selects
  655. that window or its buffer--that is entirely under the control of the
  656. command binding of the key sequence.
  657.  - Function: eventp OBJECT
  658.      This function returns non-`nil' if EVENT is an input event.
  659. * Menu:
  660. * Keyboard Events::        Ordinary characters-keys with symbols on them.
  661. * Function Keys::        Function keys-keys with names, not symbols.
  662. * Click Events::        Pushing and releasing a mouse button.
  663. * Drag Events::            Moving the mouse before releasing the button.
  664. * Button-Down Events::        A button was pushed and not yet released.
  665. * Motion Events::        Just moving the mouse, not pushing a button.
  666. * Focus Events::        Moving the mouse between frames.
  667. * Event Examples::        Examples of the lists for mouse events.
  668. * Classifying Events::        Finding the modifier keys in an event symbol.
  669.                 Event types.
  670. * Accessing Events::        Functions to extract info from events.
  671. * Strings of Events::           Special considerations for putting
  672.                   keyboard character events in a string.
  673. File: elisp,  Node: Keyboard Events,  Next: Function Keys,  Up: Input Events
  674. Keyboard Events
  675. ---------------
  676.    There are two kinds of input you can get from the keyboard: ordinary
  677. keys, and function keys.  Ordinary keys correspond to characters; the
  678. events they generate are represented in Lisp as characters.  In Emacs
  679. versions 18 and earlier, characters were the only events.
  680.    An input character event consists of a "basic code" between 0 and
  681. 255, plus any or all of these "modifier bits":
  682.      The 2**23 bit in the character code indicates a character typed
  683.      with the meta key held down.
  684. control
  685.      The 2**22 bit in the character code indicates a non-ASCII control
  686.      character.
  687.      ASCII control characters such as `C-a' have special basic codes of
  688.      their own, so Emacs needs no special bit to indicate them.  Thus,
  689.      the code for `C-a' is just 1.
  690.      But if you type a control combination not in ASCII, such as `%'
  691.      with the control key, the numeric value you get is the code for
  692.      `%' plus 2**22 (assuming the terminal supports non-ASCII control
  693.      characters).
  694. shift
  695.      The 2**21 bit in the character code indicates an ASCII control
  696.      character typed with the shift key held down.
  697.      For letters, the basic code indicates upper versus lower case; for
  698.      digits and punctuation, the shift key selects an entirely different
  699.      character with a different basic code.  In order to keep within
  700.      the ASCII character set whenever possible, Emacs avoids using the
  701.      2**21 bit for those characters.
  702.      However, ASCII provides no way to distinguish `C-A' from `C-A', so
  703.      Emacs uses the 2**21 bit in `C-A' and not in `C-a'.
  704. hyper
  705.      The 2**20 bit in the character code indicates a character typed
  706.      with the hyper key held down.
  707. super
  708.      The 2**19 bit in the character code indicates a character typed
  709.      with the super key held down.
  710.      The 2**18 bit in the character code indicates a character typed
  711.      with the alt key held down.  (On some terminals, the key labeled
  712.      ALT is actually the meta key.)
  713.    In the future, Emacs may support a larger range of basic codes.  We
  714. may also move the modifier bits to larger bit numbers.  Therefore, you
  715. should avoid mentioning specific bit numbers in your program.  Instead,
  716. the way to test the modifier bits of a character is with the function
  717. `event-modifiers' (*note Classifying Events::.).
  718. File: elisp,  Node: Function Keys,  Next: Click Events,  Prev: Keyboard Events,  Up: Input Events
  719. Function Keys
  720. -------------
  721.    Most keyboards also have "function keys"--keys which have names or
  722. symbols that are not characters.  Function keys are represented in Lisp
  723. as symbols; the symbol's name is the function key's label.  For example,
  724. pressing a key labeled F1 places the symbol `f1' in the input stream.
  725.    For all keyboard events, the event type (which classifies the event
  726. for key lookup purposes) is identical to the event--it is the character
  727. or the symbol.  *Note Classifying Events::.
  728.    Here are a few special cases in the symbol naming convention for
  729. function keys:
  730. `backspace', `tab', `newline', `return', `delete'
  731.      These keys correspond to common ASCII control characters that have
  732.      special keys on most keyboards.
  733.      In ASCII, `C-i' and TAB are the same character.  Emacs lets you
  734.      distinguish them if you wish, by returning the former as the
  735.      integer 9, and the latter as the symbol `tab'.
  736.      Most of the time, it's not useful to distinguish the two.  So
  737.      normally `function-key-map' is set up to map `tab' into 9.  Thus, a
  738.      key binding for character code 9 also applies to `tab'.  Likewise
  739.      for the other symbols in this group.  The function `read-char'
  740.      also converts these events into characters.
  741.      In ASCII, BS is really `C-h'.  But `backspace' converts into the
  742.      character code 127 (DEL), not into code 8 (BS).  This is what most
  743.      users prefer.
  744. `kp-add', `kp-decimal', `kp-divide', ...
  745.      Keypad keys (to the right of the regular keyboard).
  746. `kp-0', `kp-1', ...
  747.      Keypad keys with digits.
  748. `kp-f1', `kp-f2', `kp-f3', `kp-f4'
  749.      Keypad PF keys.
  750. `left', `up', `right', `down'
  751.      Cursor arrow keys
  752.    You can use the modifier keys CTRL, META, HYPER, SUPER, ALT and
  753. SHIFT with function keys.  The way to represent them is with prefixes
  754. in the symbol name:
  755.      The alt modifier.
  756.      The control modifier.
  757.      The hyper modifier.
  758.      The meta modifier.
  759.      The shift modifier.
  760.      The super modifier.
  761.    Thus, the symbol for the key F3 with META held down is `M-F3'.  When
  762. you use more than one prefix, we recommend you write them in
  763. alphabetical order (though the order does not matter in arguments to
  764. the key-binding lookup and modification functions).
  765. File: elisp,  Node: Click Events,  Next: Drag Events,  Prev: Function Keys,  Up: Input Events
  766. Click Events
  767. ------------
  768.    When the user presses a mouse button and releases it at the same
  769. location, that generates a "click" event.  Mouse click events have this
  770. form:
  771.      (EVENT-TYPE
  772.       (WINDOW BUFFER-POS
  773.        (COLUMN . ROW) TIMESTAMP))
  774.    Here is what the elements normally mean:
  775. EVENT-TYPE
  776.      This is a symbol that indicates which mouse button was used.  It is
  777.      one of the symbols `mouse-1', `mouse-2', ..., where the buttons
  778.      are numbered numbered left to right.
  779.      You can also use prefixes `A-', `C-', `H-', `M-', `S-' and `s-'
  780.      for modifiers alt, control, hyper, meta, shift and super, just as
  781.      you would with function keys.
  782.      This symbol also serves as the event type of the event.  Key
  783.      bindings describe events by their types; thus, if there is a key
  784.      binding for `mouse-1', that binding would apply to all events whose
  785.      EVENT-TYPE is `mouse-1'.
  786. WINDOW
  787.      This is the window in which the click occurred.
  788. COLUMN
  789.      These are the column and row of the click, relative to the top left
  790.      corner of WINDOW, which is `(0 . 0)'.
  791. BUFFER-POS
  792.      This is the buffer position of the character clicked on.
  793. TIMESTAMP
  794.      This is the time at which the event occurred, in milliseconds.
  795.      (Since this value wraps around the entire range of Emacs Lisp
  796.      integers in about five hours, it is useful only for relating the
  797.      times of nearby events.)
  798.    The meanings of BUFFER-POS, ROW and COLUMN are somewhat different
  799. when the event location is in a special part of the screen, such as the
  800. mode line or a scroll bar.
  801.    If the location is in a scroll bar, then BUFFER-POS is the symbol
  802. `vertical-scroll-bar' or `horizontal-scroll-bar', and the pair `(COLUMN
  803. . ROW)' is replaced with a pair `(PORTION . WHOLE)', where PORTION is
  804. the distance of the click from the top or left end of the scroll bar,
  805. and WHOLE is the length of the entire scroll bar.
  806.    If the position is on a mode line or the vertical line separating
  807. WINDOW from its neighbor to the right, then BUFFER-POS is the symbol
  808. `mode-line' or `vertical-line'.  For the mode line, ROW does not have
  809. meaningful data.  For the vertical line, COLUMN does not have
  810. meaningful data.
  811. File: elisp,  Node: Drag Events,  Next: Button-Down Events,  Prev: Click Events,  Up: Input Events
  812. Drag Events
  813. -----------
  814.    With Emacs, you can have a drag event without even changing your
  815. clothes.  A "drag event" happens every time the user presses a mouse
  816. button and then moves the mouse to a different character position before
  817. releasing the button.  Like all mouse events, drag events are
  818. represented in Lisp as lists.  The lists record both the starting mouse
  819. position and the final position, like this:
  820.      (EVENT-TYPE
  821.       (WINDOW1 BUFFER-POS1
  822.        (COLUMN1 . ROW1) TIMESTAMP1)
  823.       (WINDOW2 BUFFER-POS2
  824.        (COLUMN2 . ROW2) TIMESTAMP2))
  825.    For a drag event, the name of the symbol EVENT-TYPE contains the
  826. prefix `drag-'.  The second and third elements of the event give the
  827. starting and ending position of the drag.  Aside from that, the data
  828. have the same meanings as in a click event (*note Click Events::.).  You
  829. can access the second element of any mouse event in the same way, with
  830. no need to distinguish drag events from others.
  831.    The `drag-' prefix follows the modifier key prefixes such as `C-'
  832. and `M-'.
  833.    If `read-key-sequence' receives a drag event which has no key
  834. binding, and the corresponding click event does have a binding, it
  835. changes the drag event into a click event at the drag's starting
  836. position.  This means that you don't have to distinguish between click
  837. and drag events unless you want to.
  838. File: elisp,  Node: Button-Down Events,  Next: Motion Events,  Prev: Drag Events,  Up: Input Events
  839. Button-Down Events
  840. ------------------
  841.    Click and drag events happen when the user releases a mouse button.
  842. They cannot happen earlier, because there is no way to distinguish a
  843. click from a drag until the button is released.
  844.    If you want to take action as soon as a button is pressed, you need
  845. to handle "button-down" events.(1).  These occur as soon as a button is
  846. pressed.  They are represented by lists which look exactly like click
  847. events (*note Click Events::.), except that the name of EVENT-TYPE
  848. contains the prefix `down-'.  The `down-' prefix follows the modifier
  849. key prefixes such as `C-' and `M-'.
  850.    The function `read-key-sequence', and the Emacs command loop, ignore
  851. any button-down events that don't have command bindings.  This means
  852. that you need not worry about defining button-down events unless you
  853. want them to do something.  The usual reason to define a button-down
  854. event is so that you can track mouse motion (by reading motion events)
  855. until the button is released.  *Note Motion Events::.
  856.    ---------- Footnotes ----------
  857.    (1)  Button-down is the conservative antithesis of drag.
  858. File: elisp,  Node: Motion Events,  Next: Focus Events,  Prev: Button-Down Events,  Up: Input Events
  859. Motion Events
  860. -------------
  861.    Emacs sometimes generates "mouse motion" events to describe motion
  862. of the mouse without any button activity.  Mouse motion events are
  863. represented by lists that look like this:
  864.      (mouse-movement
  865.       (WINDOW BUFFER-POS
  866.        (COLUMN . ROW) TIMESTAMP))
  867.    The second element of the list describes the current position of the
  868. mouse, just as in a click event (*note Click Events::.).
  869.    The special form `track-mouse' enables generation of motion events
  870. within its body.  Outside of `track-mouse' forms, Emacs does not
  871. generate events for mere motion of the mouse, and these events do not
  872. appear.
  873.  - Special Form: track-mouse BODY...
  874.      This special form executes BODY, with generation of mouse motion
  875.      events enabled.  Typically BODY would use `read-event' to read the
  876.      motion events and modify the display accordingly.
  877.      When the user releases the button, that generates a click event.
  878.      Normally BODY should return when it sees the click event, and
  879.      discard the event.
  880. File: elisp,  Node: Focus Events,  Next: Event Examples,  Prev: Motion Events,  Up: Input Events
  881. Focus Events
  882. ------------
  883.    Window systems provide general ways for the user to control which
  884. window gets keyboard input.  This choice of window is called the
  885. "focus".  When the user does something to switch between Emacs frames,
  886. that generates a "focus event".  The normal definition of a focus event,
  887. in the global keymap, is to select a new frame within Emacs, as the user
  888. would expect.  *Note Input Focus::.
  889.    Focus events are represented in Lisp as lists that look like this:
  890.      (switch-frame NEW-FRAME)
  891. where NEW-FRAME is the frame switched to.
  892.    In X windows, most window managers are set up so that just moving the
  893. mouse into a window is enough to set the focus there.  Emacs appears to
  894. do this, because it changes the cursor to solid in the new frame.
  895. However, there is no need for the Lisp program to know about the focus
  896. change until some other kind of input arrives.  So Emacs generates the
  897. focus event only when the user actually types a keyboard key or presses
  898. a mouse button in the new frame; just moving the mouse between frames
  899. does not generate a focus event.
  900.    A focus event in the middle of a key sequence would garble the
  901. sequence.  So Emacs never generates a focus event in the middle of a key
  902. sequence.  If the user changes focus in the middle of a key
  903. sequence--that is, after a prefix key--then Emacs reorders the events
  904. so that the focus event comes either before or after the multi-event key
  905. sequence, and not within it.
  906. File: elisp,  Node: Event Examples,  Next: Classifying Events,  Prev: Focus Events,  Up: Input Events
  907. Event Examples
  908. --------------
  909.    If the user presses and releases the left mouse button over the same
  910. location, that generates a sequence of events like this:
  911.      (down-mouse-1 (#<window 18 on NEWS> 2613 (0 . 38) -864320))
  912.      (mouse-1      (#<window 18 on NEWS> 2613 (0 . 38) -864180))
  913.    Or, while holding the control key down, the user might hold down the
  914. second mouse button, and drag the mouse from one line to the next.
  915. That produces two events, as shown here:
  916.      (C-down-mouse-2 (#<window 18 on NEWS> 3440 (0 . 27) -731219))
  917.      (C-drag-mouse-2 (#<window 18 on NEWS> 3440 (0 . 27) -731219)
  918.                      (#<window 18 on NEWS> 3510 (0 . 28) -729648))
  919.    Or, while holding down the meta and shift keys, the user might press
  920. the second mouse button on the window's mode line, and then drag the
  921. mouse into another window.  That produces the following pair of events:
  922.      (M-S-down-mouse-2 (#<window 18 on NEWS> mode-line (33 . 31) -457844))
  923.      (M-S-drag-mouse-2 (#<window 18 on NEWS> mode-line (33 . 31) -457844)
  924.                        (#<window 20 on carlton-sanskrit.tex> 161 (33 . 3)
  925.                         -453816))
  926.